<?php

class AuthController extends Zend_Controller_Action{

  public function indexAction(){


  }

  public function loginAction(){

    $this->view->form = $this->getLoginForm();
    
  }
  
  public function processAction(){
    
    $this->_helper->viewRenderer->setNoRender();
    $form = $this->getLoginForm();
    if(!$form->isValid($_POST)){
      
      $this->view->form = $form;
      return $this->render('login');
    }
    
    }

  public function getLoginForm(){

    $form = new Zend_Form();
    $form->setAction('/auth/process')
    ->setAttrib('id', 'login')
    ->setMethod('post');
     
    $username = $form->createElement('text', 'username', array('label' => 'Username'));
    $username->addValidator('regex', false, array('/^[0-9a-z_]{5,32}+$/', 'messages' => array('regexNotMatch' => '5 to 32 characters containing a-z, 0-9 and "_" Only.')))
             ->setRequired(true);
    $password = $form->createElement('password', 'password', array('label' => 'Password'));
    $password->addValidator('regex', false, array('/^.{6,32}$/', 'messages' => array('regexNotMatch' => '6 to 32 characters Only.')))
             ->setRequired(true);
    $submit = $form->createElement('submit', 'Login');
             
    $form->addElement($username)
         ->addElement($password)
         ->addElement($submit);
    return $form;
  }

}